/*
 * Copyright (c) Huawei Technologies Co.,Ltd. 2023. All rights reserved.
 */
package org.opengauss;

import com.hybench.load.DataImport;

import java.sql.Connection;
import java.sql.Statement;

/**
 * Title: the OpenGaussDataImport class.
 * <p>
 * Description:
 *
 * @author justbk
 * @version [Tools 0.0.1, 2023/5/13]
 * @since 2023/5/13
 */
public class OpenGaussDataImport implements DataImport {
    public static String COPY_FORMAT = "copy %s from '%s' with delimiter as ',' null as 'null' csv;";
    @Override
    public void doDataImport(Connection conn, final String tableName, final String dataFile) throws Exception {
        try (Statement st = conn.createStatement()) {
            String sql = String.format(COPY_FORMAT, tableName, dataFile);
            System.out.println("dataImport:" + sql);
            st.execute(sql);
        }
        conn.commit();
    }
    
    @Override
    public String getDbType() {
        return "openGauss";
    }
}
